package org.vectrics.recruiter.struts.tag;

import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Category;
import org.vectrics.employee.MedicalInsurance;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.struts.VectricsTagSupport;

public class MedicalInsuranceComboTag extends VectricsTagSupport{
	private static final long serialVersionUID = 5419398022635962033L;
	static private Category log = Category.getInstance(MedicalInsuranceComboTag.class);
    private String styleClass = null;
    private String property = null;
    private String value = null;
    
    
	public MedicalInsuranceComboTag() {
		super();
	}

	public String makeStartTag() {
		StringBuffer html = new StringBuffer();
		
		log.debug("doStartTag() called");
		HttpServletRequest request = (HttpServletRequest)super.pageContext.getRequest();
		String propValue = request.getParameter(property);
		log.debug("propValue = " + propValue);
		
		if (styleClass == null) {
			html.append("<select name=\"" + this.property + "\" style=\"width:350;font-family:verdana,arial,sans serif;font-size=11px\">");
		} else {
			html.append("<select name=\"" + this.property + "\" class=\"" + styleClass + "\">");
		}
		
		Iterator iter = RecruitServiceLocator.getEmployeeService().getEmployeesMedicalInsurance().iterator();
		while (iter.hasNext()) {
			MedicalInsurance insurance = (MedicalInsurance)iter.next();
			String selectStr = "";
			if (insurance.getCode().equals(this.value)) {
				selectStr = "SELECTED";
			}
			html.append("<option " + selectStr + " value=\"" + insurance.getCode() + "\">" 
					+ insurance.getDescription()	+ "</option>");
		}
		html.append("</select>");

		return(html.toString());
	}

	/**
	 * @return
	 */
	public String getStyleClass() {
		return styleClass;
	}

	/**
	 * @param styleClass
	 */
	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}

	/**
	 * @return
	 */
	public String getProperty() {
		return property;
	}

	/**
	 * @param property
	 */
	public void setProperty(String property) {
		this.property = property;
	}

	/**
	 * @return Returns the value.
	 */
	public String getValue() {
		return value;
	}
	/**
	 * @param value The value to set.
	 */
	public void setValue(String value) {
		this.value = value;
	}
	
}
